package com.fjzx.androidframe.base.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * @author xiongyongcong
 */
public class AspectJUtil {
    public static <T extends Annotation> T getMethodAnnotation(ProceedingJoinPoint joinPoint, Class<T> clazz) {
        Method realMethod = null;
        try {
            MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
            Method method = methodSignature.getMethod();
            realMethod = joinPoint.getTarget().getClass().getDeclaredMethod(methodSignature.getName(), method.getParameterTypes());
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return realMethod == null ? null : realMethod.getAnnotation(clazz);
    }
}
